﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Data;
using DataAccess;
using Utility;

namespace Web.giamthi
{
    public partial class UCThongBao : System.Web.UI.UserControl
    {
        ThongBaoControl tbCtr = new ThongBaoControl();
        ThongBao tb = new ThongBao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                GridView1.AllowPaging = true;
                GridView1.PageSize = 15;
                LoadThongBao();
            }
        }

        // hiển thị danh sách thông báo
        private void LoadThongBao()
        {
            GridView1.DataSource = tbCtr.GetListThongBao();
            GridView1.DataBind();
        }

        // chọn 1 dòng để update
        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            string id = WebHelper.GetIdGridView(GridView1 , 0 ,e).ToString();
            Response.Redirect("admin.aspx?page=taothongbao&id="+id.ToString()+"");
        }

        // xóa
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = Int32.Parse(WebHelper.GetDataKey(GridView1 , e).ToString());
            tb.MaTB = id;
            tbCtr.DeleteThongBao(tb);
            LoadThongBao();
        }

        // phân trang
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            WebHelper.pageIndexChanging(GridView1 , e);
            LoadThongBao();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            WebHelper.ConfirmDelete("Bạn muốn xóa dòng này ?", e);
        }
    }
}